package com.example.xbrother.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * 直接用map接收数据
 */
@Slf4j
public class NoModelDataListener extends AnalysisEventListener<Map<Integer, String>> {
    /**
     * excel表头数据
     */
    private Map<Integer, String> cachedHeadMap = new HashMap<>();

    @Override
    public void invoke(Map<Integer, String> data, AnalysisContext context) {
        //log.info("解析到一条数据:{}", JSON.toJSONString(data));
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        log.info("所有数据解析完成！");
    }

    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        //log.info("解析到表头数据:{}", JSON.toJSONString(headMap));
        cachedHeadMap = headMap;
    }

    /**
     * 获取表头数据
     */
    public Map<Integer, String> getCachedHeadMap() {
        return cachedHeadMap;
    }
}
